package com.gengzp.system.controller;

import com.gengzp.common.annotations.OperationLogIgnore;
import com.gengzp.common.model.generic.req.SearchByIdReq;
import com.gengzp.common.model.generic.resp.Result;
import com.gengzp.common.model.pagination.resp.PaginationResponse;
import com.gengzp.common.model.role.req.CreateSysRoleReq;
import com.gengzp.common.model.role.req.EditSysRoleReq;
import com.gengzp.common.model.role.req.PageSysRoleReq;
import com.gengzp.common.model.role.resp.PageSysRoleResp;
import com.gengzp.common.model.role.resp.SearchSysRoleResp;
import com.gengzp.permission.annotation.CheckPermission;
import com.gengzp.system.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SysRoleController
 * @Description 系统角色控制层
 * @Author gengzp
 * @Date 2025/9/8 19:33
 */
@RestController
@RequestMapping("/role")
@Api(tags = "系统角色管理模块")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 添加系统角色
     */
    @PostMapping("/create")
    @ApiOperation(value = "添加系统角色")
    @CheckPermission(value = "role:write:create")
    public Result<Void> createSysRole(@Valid @RequestBody CreateSysRoleReq req) {
        sysRoleService.createSysRole(req);
        return Result.getSuccessResult();
    }

    /**
     * 编辑系统角色
     */
    @PostMapping("/edit_by_id")
    @ApiOperation(value = "编辑系统角色")
    @CheckPermission(value = "role:write:edit")
    public Result<Void> editSysRoleById(@Valid @RequestBody EditSysRoleReq req) {
        sysRoleService.editSysRoleById(req);
        return Result.getSuccessResult();
    }

    /**
     * 根据id删除角色
     */
    @PostMapping("/remove_by_id")
    @ApiOperation(value = "根据id删除角色")
    @CheckPermission(value = "role:write:remove")
    public Result<Void> removeSysRoleById(@Valid @RequestBody SearchByIdReq req) {
        sysRoleService.removeSysRoleById(Long.valueOf(req.getId()));
        return Result.getSuccessResult();
    }

    /**
     * 根据id查询角色详情
     */
    @OperationLogIgnore
    @PostMapping("/search_by_id")
    @ApiOperation(value = "根据id查询角色详情")
    @CheckPermission(value = "role:read")
    public Result<SearchSysRoleResp> searchSysRoleById(@Valid @RequestBody SearchByIdReq req) {
        return Result.getSuccessResult(sysRoleService.searchSysRoleById(Long.valueOf(req.getId())));
    }

    /**
     * 分页查询角色详情
     */
    @OperationLogIgnore
    @PostMapping("/page")
    @ApiOperation(value = "分页查询角色详情")
    @CheckPermission(value = "role:read")
    public Result<PaginationResponse<PageSysRoleResp>> pageQuerySysRole(@Valid @RequestBody PageSysRoleReq req) {
        return Result.getSuccessResult(sysRoleService.pageQuerySysRole(req));
    }

}
